define(['./style', 'lodash'], function(style, _) {

  function randomData() {
    now = new Date(+now + step);
    value = value + Math.random() * 21 - 10;
    date.push(now)
    return {
        name: now.toString(),
        value: [
            now,
            Math.round(value)
        ]
    }
  }

  var data = [];
  var date = []
  var now = +new Date(1997, 9, 3) + 450 * 1000;
  var step = 10 * 1000;
  var value = Math.random() * 1000;
  for (var i = 0; i < 202; i++) {
      data.push(randomData());
  }

  date.sort(function(a,b) {
    return a - b
  })

  var min = date[0];
  var max = date[date.length - 1];

  var interval = (max - min) / 6

  var option = {
    title: {
      //text: '服务器A与服务器B的CPU使用率趋势图',
      textStyle: {
        color: style.title.textStyle.color,
        fontSize: style.title.textStyle.fontSize
      }
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        lineStyle: {
          color: style.chartBorderColor
        }
      }
    },
    legend: {
      orient: 'horizontal',
      right: 58,
      // left: 'right',
      top: style.legendPos.top,
      textStyle: {
        fontSize: style.fontSize,
        color: style.fontColor
      },
      show: true,
      data: [{ name: '服务器A' }]
    },
    grid: {
      top: style.gridPos.legendTop,
      left: style.gridPos.left,
      right: style.gridPos.right,
      bottom: style.gridPos.bottom,
      containLabel: true
    },
    toolbox: {
      show: true
    },
    xAxis: {
      type: 'time',
      min: min,
      max: max,
      interval: interval,
      // splitNumber: 20,
      nameTextStyle: {
        color: style.fontColor,
        opacity: style.opacity,
        fontSize: style.fontSize
      },
      axisLine: { //轴，下面有条是grid线，
        show: true,
        onZero: true,
        lineStyle: {
          color: style.axisLineColor,
          width: style.axisLine.lineStyle.width,
          opacity: style.notSupportOpacity
        }
      },
      axisTick: { //刻度
        show: false
      },
      axisLabel: {
        show: true,
        margin: 8,
        rotate: 0,
        textStyle: {
          color: style.labelColor,
          opacity: style.notSupportOpacity,
          fontSize: style.fontSize
        }
      },
      splitLine: {
        show: false,
        lineStyle: {
          color: '#236592',
          opacity: style.opacity
        }
      }
    },
    yAxis: {
      max: undefined,
      min: undefined,
      //interval: undefined,
      nameTextStyle: {
        color: style.fontColor,
        opacity: style.opacity,
        fontSize: style.fontSize
      },
      axisLine: { //轴，下面有条是grid线，
        show: true,
        onZero: false,
        lineStyle: {
          color: style.axisLineColor,
          width: style.axisLine.lineStyle.width,
          opacity: style.notSupportOpacity
        }
      },
      axisTick: { //刻度
        show: false
      },
      axisLabel: {
        show: true,
        margin: 8,
        rotate: 0,
        textStyle: {
          color: style.labelColor,
          opacity: style.notSupportOpacity,
          fontSize: style.fontSize
        }
      },
      splitLine: {
        show: false,
        lineStyle: {
          color: '#236592',
          opacity: style.opacity
        }
      }
    },
    series: [{
      name: '服务器A',
      type: 'line',
      showSymbol: true, //自加属性
      symbol: 'circle',
      symbolSize: 5,
      lineMode: 1, //自行设定的折线属性 1为平滑折线 2为普通折线 3为阶梯折线
      step: false,
      smooth: 0.3,
      lineStyle: {
        normal: {
          opacity: 1
        }
      },
      areaStyle: {
        normal: {
          show: true,
          opacity: 0.2
        }
      },
      data: data
    }]
  };

  return option;
})
